package com.huawei.gamebox.support.widget;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.LinearInterpolator;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import o.Logger;
import o.exp$e;
import o.exp$h;
import o.exp$i;

public class ErrorTipTextLayout extends LinearLayout {
    private int ʻ;
    private boolean ʼ;
    private int ʽ;
    private EditText ˊ;
    private int ˋ;
    private boolean ˎ;
    private c ˏ;
    private TextView ॱ;
    private int ॱॱ;

    static class b implements TextWatcher {
        private b() {
        }

        public void afterTextChanged(Editable editable) {
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }
    }

    public enum c {
        Bubble,
        Linear
    }

    class e extends AccessibilityDelegate {
        final /* synthetic */ ErrorTipTextLayout ˏ;

        private e(ErrorTipTextLayout errorTipTextLayout) {
            this.ˏ = errorTipTextLayout;
        }

        public void onInitializeAccessibilityEvent(View view, AccessibilityEvent accessibilityEvent) {
            super.onInitializeAccessibilityEvent(view, accessibilityEvent);
            accessibilityEvent.setClassName(ErrorTipTextLayout.class.getSimpleName());
        }

        public void onPopulateAccessibilityEvent(View view, AccessibilityEvent accessibilityEvent) {
            super.onPopulateAccessibilityEvent(view, accessibilityEvent);
        }

        @TargetApi(21)
        public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfo accessibilityNodeInfo) {
            super.onInitializeAccessibilityNodeInfo(view, accessibilityNodeInfo);
            accessibilityNodeInfo.setClassName(ErrorTipTextLayout.class.getSimpleName());
            if (this.ˏ.ˊ != null) {
                accessibilityNodeInfo.setLabelFor(this.ˏ.ˊ);
            }
            CharSequence text = this.ˏ.ॱ != null ? this.ˏ.ॱ.getText() : null;
            if (!TextUtils.isEmpty(text)) {
                accessibilityNodeInfo.setContentInvalid(true);
                accessibilityNodeInfo.setError(text);
            }
        }
    }

    public ErrorTipTextLayout(Context context) {
        this(context, null);
    }

    public ErrorTipTextLayout(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    @TargetApi(16)
    public ErrorTipTextLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet);
        setOrientation(1);
        setAddStatesFromChildren(true);
        this.ʻ = exp$e.ˊ;
        this.ʽ = exp$e.ॱ;
        this.ॱॱ = exp$e.ʻ;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, exp$h.ॱʼ, i, exp$i.ॱ);
        try {
            this.ˋ = obtainStyledAttributes.getResourceId(exp$h.ॱʻ, 0);
            boolean z = obtainStyledAttributes.getBoolean(exp$h.ॱʽ, true);
            this.ʼ = obtainStyledAttributes.getBoolean(exp$h.ॱͺ, false);
            this.ˏ = c.values()[obtainStyledAttributes.getInt(exp$h.ـ, c.Bubble.ordinal())];
            setErrorEnabled(z);
        } catch (Throwable e) {
            Logger.ˋ("ErrorTipTextLayout", "getReource exception", e);
        } finally {
            obtainStyledAttributes.recycle();
        }
        if (getImportantForAccessibility() == 0) {
            setImportantForAccessibility(1);
        }
        setAccessibilityDelegate(new e());
    }

    public void addView(View view, int i, LayoutParams layoutParams) {
        if (view instanceof EditText) {
            ˎ((EditText) view);
            super.addView(view, 0, ˏ(layoutParams));
            return;
        }
        super.addView(view, i, layoutParams);
    }

    private LinearLayout.LayoutParams ˏ(LayoutParams layoutParams) {
        return layoutParams instanceof LinearLayout.LayoutParams ? (LinearLayout.LayoutParams) layoutParams : new LinearLayout.LayoutParams(layoutParams);
    }

    @TargetApi(17)
    private void ˎ(EditText editText) {
        if (this.ˊ != null) {
            throw new IllegalArgumentException("We already have an EditText, can only have one");
        }
        this.ˊ = editText;
        this.ˊ.setImeOptions(this.ˊ.getImeOptions() | 33554432);
        if (this.ˏ == c.Bubble) {
            this.ˊ.setBackgroundResource(this.ʻ);
        } else if (this.ˏ == c.Linear) {
            this.ˊ.setBackgroundResource(this.ʽ);
        }
        this.ˊ.addTextChangedListener(new b());
        if (this.ॱ != null) {
            this.ॱ.setPaddingRelative(this.ˊ.getPaddingStart(), 0, this.ˊ.getPaddingEnd(), 0);
        }
    }

    public void setHint(@Nullable CharSequence charSequence) {
        this.ˊ.setHint(charSequence);
        sendAccessibilityEvent(2048);
    }

    @TargetApi(17)
    public void setErrorEnabled(boolean z) {
        if (this.ˎ != z) {
            if (this.ॱ != null) {
                this.ॱ.animate().cancel();
            }
            if (z) {
                this.ॱ = new TextView(getContext());
                this.ॱ.setTextAppearance(getContext(), this.ˋ);
                this.ॱ.setVisibility(this.ʼ ? 4 : 8);
                addView(this.ॱ);
                if (this.ˊ != null) {
                    this.ॱ.setPaddingRelative(this.ˊ.getPaddingStart(), 0, this.ˊ.getPaddingEnd(), 0);
                }
            } else {
                removeView(this.ॱ);
                this.ॱ = null;
            }
            this.ˎ = z;
        }
    }

    @TargetApi(21)
    public void setError(@Nullable CharSequence charSequence) {
        if (!this.ˎ) {
            if (!TextUtils.isEmpty(charSequence)) {
                setErrorEnabled(true);
            } else {
                return;
            }
        }
        if (!TextUtils.isEmpty(charSequence)) {
            this.ॱ.setAlpha(0.0f);
            this.ॱ.setText(charSequence);
            this.ॱ.animate().alpha(1.0f).setDuration(200).setInterpolator(new LinearInterpolator()).setListener(new AnimatorListenerAdapter(this) {
                final /* synthetic */ ErrorTipTextLayout ˎ;

                {
                    this.ˎ = r1;
                }

                public void onAnimationStart(Animator animator) {
                    this.ˎ.ॱ.setVisibility(0);
                }
            }).start();
            if (this.ˏ == c.Bubble) {
                this.ˊ.setBackgroundResource(this.ॱॱ);
            } else if (this.ˏ == c.Linear) {
                this.ˊ.setBackgroundTintList(ColorStateList.valueOf(this.ॱ.getCurrentTextColor()));
            }
        } else if (this.ॱ.getVisibility() == 0) {
            this.ॱ.animate().alpha(0.0f).setDuration(200).setInterpolator(new LinearInterpolator()).setListener(new AnimatorListenerAdapter(this) {
                final /* synthetic */ ErrorTipTextLayout ॱ;

                {
                    this.ॱ = r1;
                }

                public void onAnimationEnd(Animator animator) {
                    this.ॱ.ॱ.setVisibility(this.ॱ.ʼ ? 4 : 8);
                }
            }).start();
            if (this.ˏ == c.Bubble) {
                this.ˊ.setBackgroundResource(this.ʻ);
            } else if (this.ˏ == c.Linear) {
                this.ˊ.setBackgroundTintList(null);
            }
        }
        sendAccessibilityEvent(2048);
    }
}
